import { Message } from 'element-ui';
// const lis = ['请求取消！'];
const myAlert = (res,close) => {
    // console.log(res);
    // if (res.hasOwnProperty('msg') && lis.includes(res.msg)){
    //   return false;
    // }
    let message = ``;
    if (!res || res === 'undefined'){
        message = `undefined`;
    } else if (Object.prototype.toString.call(res) === '[object String]'){
        message = `<p>${res}</p>`;
    }else if (res.hasOwnProperty('code') && res.hasOwnProperty('msg')){
        message = `<p>状态码：${res.code}</p><p>提示：${res.msg}</p>`
    } else {
        for (const key in res) {
            // console.log(key);
            if (res.hasOwnProperty(key)) {
                const element = res[key];
                message += `<p>${key}：${element}</p>`
            }
        }
    }
    if(close){//先清除message
        Message.closeAll();
    }
    // alert('状态码：' + res.code + ' 提示：' + res.msg);
    Message({
        dangerouslyUseHTMLString: true,
        message:message,
        type: 'warning',
        duration: 0,
        customClass: 'alertTipsMsg tipsMsg',
        showClose: true
    })
    return res;
};

export {
    myAlert
}
